"""
迭代器:
    迭代器是一个可以被逐个访问的对象
里面有二个方法
    __iter__()
    __next__()
"""
# list1=[12,3,4,1]
# iter1=iter(list1) # 创建迭代器对象
# print(next(iter1)) # 调用next方法

class MyRange:
    def __init__(self, start, end,step=1):
        self.current = start
        self.end = end
        self.step = step
    def __iter__(self):
        return self
    def __next__(self):
        if self.current < self.end:
            val = self.current
            self.current += self.step
            return val
        else:
            raise StopIteration

for i in MyRange(1, 5):
    print(i)  # 输出 1 到 4





